const dayjs = require('dayjs')
// 过滤器, 显示的时间格式
const displayDate = (date) => {
  if (!date) return
  return dayjs(date).format('YYYY-MM-DD')
}
// 过滤器, 显示的时间格式
const dateMimute = (date) => {
  if (!date) return
  return dayjs(date).format('YYYY-MM-DD HH:mm')
}
// 金额过滤器, 没有￥
const moneyShow = (num) => {
  var numb = (num === '' ? '' : +num)
  // var numb = (+num === '' ? '' : +num)
    .toString()
    .replace(/^-?\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
  numb === '￥' ? (numb = '0.00') : numb
  // numb === '￥' ? (numb = '0.00') : numb
  return numb
}

// 金额过滤器, 有￥
const toThous = (num) => {
  var numb =
    '￥' +
    (+num || '')
      .toString()
      .replace(/^-?\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
  numb === '￥' ? (numb = '￥0.00') : numb

  if (numb.indexOf('.') === -1) {
    numb = numb + '.00'
  }
  if (numb.toString().split('.')[1].length === 1) {
    numb = numb + '0'
  }
  return numb
}
// 金额过滤器,  不加两位小数点的
const toThousNoDec = (num) => {
  if (!num) return 0
  var numb =
    '￥' +
    (+num || '')
      .toString()
      .replace(/^-?\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
  numb === '￥' ? (numb = '￥0') : numb
  return numb
}
export { displayDate, dateMimute, toThous, toThousNoDec, moneyShow }
